package com.mine.mybatis.session;

import com.mine.mybatis.bulider.xml.XMLConfigBuilder;
import com.mine.mybatis.session.defaults.DefaultSqlSessionFactory;
import org.dom4j.DocumentException;

import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException {

        // 1.使用dom4j解析配置文件，将解析出来的内容封装到Configuration
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        // 2.通过xmlConfigBuilder 解析配置文件以及sql映射文件，完成configuration对象的封装
        Configuration configuration  = xmlConfigBuilder.parse(inputStream);

        return this.build(configuration);
    }

    //工厂方法模式
    public SqlSessionFactory build(Configuration configuration) {

        return new DefaultSqlSessionFactory(configuration);
    }



}
